﻿Imports System.Resources

Public Class frmNouvSite

    Private rm As New ResourceManager(GetType(frmNouvSite))
    Private test As String
    Private s, alti, strAlti As String
    Private wDop As String
    Private DblAlti, DblPrecision, dblDOP As Double
    Private _strLatitude, _strLongitude, _strAltitude, _strDop, strlbDop As String
    Private _strCoordonnesGPS As String
    Private intLong As Short

    Public Property strLatitude() As String
        Get
            Return _strLatitude
        End Get
        Set(ByVal value As String)
            _strLatitude = value
            actualiserGPS()

        End Set
    End Property

    Public Property strLongitude() As String
        Get
            Return _strLongitude
        End Get
        Set(ByVal value As String)
            _strLongitude = value
            actualiserGPS()

        End Set
    End Property

    Public Property strAltitude() As String
        Get
            Return _strAltitude
        End Get
        Set(ByVal value As String)
            _strAltitude = value
            actualiserGPS()

        End Set
    End Property


    Public Property strDop() As String
        Get
            Return _strDop
        End Get
        Set(ByVal value As String)
            _strDop = value
            actualiserGPS()
        End Set
    End Property


    Private Sub lbPrecision_textChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPrecision.TextChanged
        s = lblPrecision.Text
    End Sub


    Private Sub actualiserGPS()
       
        If (m_isFormGPSOpen = True) And (m_isGpsInterpreteurOpen = True) And (_strLongitude <> "0") And (_strLongitude <> "") And (_strLongitude <> Nothing) And (_strLongitude <> Nothing) Then
            'lblLatitude.Text = frmParamGPS.TXT_Latitude.Text
            'lblLongitude.Text = frmParamGPS.TXT_Longitude.Text
            'lblAltitude.Text = frmParamGPS.TXT_Altitude.Text
            'lbDop.Text = frmParamGPS.TXT_Dop.Text
            'frmParamGPS.TXT_Dop.Text = Replace(frmParamGPS.TXT_Dop.Text, ".", ",")
            'lbPrecision.Text = 7 * (CType(frmParamGPS.TXT_Dop.Text, Double))
            'CalculatePrecision(frmParamGPS.TXT_Dop.Text, preci_cadre.Width, Preci)

            ' _strCoordonnesGPS = frmParamGPS0.Tag

            wDop = _strDop

            lblLatitude.Text = _strLatitude
            lblLongitude.Text = _strLongitude
            lblAltitude.Text = _strAltitude
            'Si le signal n'est pas informatif = Pas de DOP ou alors trop important (50)
            'On ne traite pas l'information de la trame
            If (wDop = "" Or wDop = "0" Or wDop = "50") Or (lblLatitude.Text = "0") Then
                lblDop.Text = "50"
            Else : lblDop.Text = wDop
            End If
            lblPrecision.Text = 7 * (CType(Replace(lblDop.Text, ".", ","), Double))
            'lblPrecision.Text = 7 * (CInt(lblDop.Text))


        Else


            'Not (frmParamGPS.oCurrentDevice.IsOpen) Or (frmParamGPS.NmeaInterpreter1.IsDisposed = True) Or _strLongitude = "0" Or _strLongitude = "" Then
            ' If frmParamGPS.LST_Ports.SelectedIndex = -1 Or frmParamGPS.TXT_Latitude.Text = "0" Or frmParamGPS.TXT_Latitude.Text = "" Then 'Gère la non selection de port
            '  frmParamGPS.BOU_Ouvrir.Enabled = False
            ' MsgBox(DirectCast(My.Resources.Images.alertNoGPS, String), MsgBoxStyle.Exclamation, "Pocket eRelevé")
            lblLatitude.Text = Nothing
            lblLongitude.Text = Nothing
            lblAltitude.Text = Nothing
            lblPrecision.Text = Nothing
            lblDop.Text = Nothing


        End If

    End Sub


    'Private Sub btnPos_GPS_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPos_GPS.Click
    '    If frmParamGPS1.LST_Ports.SelectedIndex = -1 Or frmParamGPS1.TXT_Latitude.Text = "0" Or frmParamGPS1.TXT_Latitude.Text = "" Then 'Gère la non selection de port
    '        frmParamGPS1.BOU_Ouvrir.Enabled = False
    '        MsgBox(DirectCast(My.Resources.Images.alertNoGPS, String), MsgBoxStyle.Critical, "Pocket eRelevé")
    '        Exit Sub
    '    Else
    '        lblLatitude.Text = frmParamGPS1.TXT_Latitude.Text
    '        lblLongitude.Text = frmParamGPS1.TXT_Longitude.Text
    '        lblAltitude.Text = frmParamGPS1.TXT_Altitude.Text
    '        lblDop.Text = frmParamGPS1.TXT_Dop.Text
    '        lblPrecision.Text = 7 * (CType(Replace(lblDop.Text, ".", ","), Double))
    '    End If
    'End Sub

    Private Sub btnAjouterNouvoSite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAjouterNouvoSite.Click
        'Test s'il y a une valeur saisie
        'S'il n'y a rien = Non valide
        If Me.tb_NomSite.Text = "" Then
            MsgBox(DirectCast(My.Resources.Images.alertSiteName, String), MsgBoxStyle.Exclamation, "Pocket eRelevé")
        Else
            Try
                ' Si la liste des sites est vide = Création des entêtes de la liste
                If frmEntryChoixSite.lstViewSite.Items.Count = 0 Then
                    CreateHeadersToListView("id;site;latitude;longitude;altitude;precision", frmEntryChoixSite.lstViewSite)
                End If
                'Ajout du site à la liste en cours
                'pour un nouveau site on met un id vide
                PutDataIntoListView(";" & tb_NomSite.Text & ";" & lblLatitude.Text & ";" & lblLongitude.Text & ";" & lblAltitude.Text & ";" & lblPrecision.Text, frmEntryChoixSite.lstViewSite)
                tb_NomSite.Text = " "
                ArrangeListView(frmEntryChoixSite.lstViewSite, 1)
                MsgBox(DirectCast(My.Resources.Images.alertSiteAdd, String))
                Me.Hide()
                frmParamSite.Show()
            Catch ex As Exception
                MsgBox(DirectCast(My.Resources.Images.errorSiteNotAdd, String) & ex.Message, MsgBoxStyle.Critical, "Pocket eRelevé")
            End Try
        End If
    End Sub

    Private Sub btnRetourMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetourMenu.Click
        ClSIP.HideSIP()
        Me.Hide()
        FormMain.Show()
    End Sub

    Private Sub btnRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetour.Click
        ClSIP.HideSIP()
        Me.Hide()
        frmParamChoix.Show()
    End Sub

    Private Sub Clavier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clavier.Click
        Me.tb_NomSite.Focus()
        ClSIP.ChangeState()
    End Sub

    Private Sub frmNouvSite_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        actualiserGPS()
    End Sub
End Class